package auth

import "beergo/lib/event"
import "beergo/lib/tool"
import "github.com/beego/beego/v2/server/web/context"

func init() {
	//AdminGroupAuth()
}

func AdminGroupAuth() {
	event.ListenJoin("AdminGroupAuth", func(v interface{},ctx *context.Context) {
		url := ctx.Input.URL()
        		access := true
        		message := "access granted!"
        		switch url {
        		case "/admin/AdminGroup/info":
        			access = true
        		case "/admin/AdminGroup/scan":
        			access = true
        		case "/admin/AdminGroup/list":
        			access = true
        		case "/admin/AdminGroup/create":
        			access = true
        		case "/admin/AdminGroup/update":
        			access = true
        		case "/admin/AdminGroup/edit":
        			access = true
        		case "/admin/AdminGroup/copy":
        			access = true
        		case "/admin/AdminGroup/delete":
        			access = false
        			message = "access denied!"
        		case "/admin/AdminGroup/choice":
        			access = true
        		case "/admin/AdminGroup/category":
        			access = true
        		default:
        			if len(tool.MatchAll(url, "/admin/AdminGroup/[0-9]"))>0 {
        				//edit
        				access = true
        			}else if  len(tool.MatchAll(url, "/admin/AdminGroup/[0-9]/(.+?)"))>0  {
        				access = true
        			}else{
        				access = true
        			}
        		}
        		auth ,_ := v.(*event.AuthEvent)
        		auth.Access = access
        		auth.Message = message
	})
}